<template>
    <div class="app-container">
        <div v-show="$route.path == '/management8s'">
            <section>
                <div class="content" v-loading="loading">
                    <div class="line-box-top">
                        <div class="chunk">
                            <div class="chunk-title"> 巡查人：</div>
                            <el-input v-model="form.keys" placeholder="搜索" style="width:100%" suffix-icon="el-icon-search" ></el-input>
                        </div>
                        <div class="chunk">
                            <div class="chunk-title"> 巡查时间：</div>
                            <el-date-picker v-model="value" type="date" placeholder="选择日期"> </el-date-picker>
                        </div>
                        
                        <div class="chunk right">
                            <el-button plain>导入</el-button>
                            <el-button type="danger">删除</el-button>
                            <el-button size="medium" @click="utils.goUrl('/details8S?type=2')" type="primary">新建</el-button>
                        </div>
                    </div>
                    <div class="line-box-top">
                        <div class="chunk ">
                            <div class="chunk-title">责任部门：</div>
                            <el-select :value="1" placeholder="请选择" style="100%">
                                <el-option label="审批中"  :value="1"> </el-option> 
                                <el-option label="已完成" :value="2"> </el-option> 
                            </el-select>
                        </div>
                        <div class="chunk ">
                            <div class="chunk-title">责任人：</div>
                           <el-input v-model="form.keys" placeholder="搜索" style="width:100%" suffix-icon="el-icon-search" ></el-input>
                        </div>
                        <div class="chunk ">
                            <div class="chunk-title">解决人：</div>
                           <el-input v-model="form.keys" placeholder="搜索" style="width:100%" suffix-icon="el-icon-search" ></el-input>
                        </div>
                    </div>
                    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%;margin-top:10px;" :header-cell-style="{background:'#f5f6f8'}">
                        <el-table-column type="selection" width="55"> </el-table-column>
                        <el-table-column prop="id" label="序号"> </el-table-column>
                        <el-table-column prop="title" label="巡查人"> </el-table-column>
                        <el-table-column prop="stock" label="巡查人编号"> </el-table-column>
                        <el-table-column prop="create_time" label="巡查时间"> </el-table-column>
                        <el-table-column prop="stock" width="180" label="存在问题"> </el-table-column>
                        <el-table-column prop="stock" label="责任部门"> </el-table-column>
                        <el-table-column prop="stock" label="责任人"> </el-table-column>
                        <el-table-column prop="create_time" label="解决人"> </el-table-column>
                        <el-table-column prop="stock" label="解决方案"> </el-table-column>
                        <el-table-column prop="stock" label="处罚金额"> </el-table-column>
                        <el-table-column label="操作" width="180">
                            <template slot-scope="scope">
                                <el-button @click="handleClick(scope.row,1)" type="info" size="mini">详情</el-button>
                                <el-button @click="handleClick(scope.row,2)" type="danger" size="mini">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination style="margin-top: 40px;text-align: center;padding-bottom: 20px;" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="form.page" :page-sizes="[10, 20, 50, 100]" :page-size="form.limit" layout="total, sizes, prev, pager, next, jumper" :total="form.total">
                    </el-pagination>
                </div>
            </section>
        </div>
        <router-view></router-view>
    </div>
</template>

<script>

export default {
    data() {
        var password = (rule, value, callback) => {
            if (!value) {
                callback(new Error('请输入密码'));
            } else if (value.toString().length < 6 || value.toString().length > 20) {
                callback(new Error('密码长度为6 - 20个字符'))
            } else {
                callback();
            }
        };
        return {
            value:'',
            form: {
                keys: '',
                total: 0,
                limit: 10,
                page: 1,
            },
            id: '',
            tableData: [],
            loading: false,
        }
    },
    created() {

    },
    mounted() {
        // this.getCompanyList()
    },
    methods: {
        async sort(row) {
            console.log(row)
            await this.$Http.changeGoods({ id: row.id, field: 'sort', value: row.sort })
        },
        async handleStatus(row) {
            if (row.status == 1) {
                row.status = 0
            } else {
                row.status = 1
            }
            await this.$Http.changeGoods({ id: row.id, field: 'status', value: row.status })
        },
        // 获取产品列表
        async getCompanyList(page) {
            if (page) {
                this.form.page = page
            }
            this.loading = true
            let res = await this.$Http.getGoods(this.form)
            if (res.status == 1) {
                this.tableData = res.data.data || []
                this.form.total = res.data.total
                for (let i in this.tableData) {
                    this.tableData[i].srcList = [this.tableData[i].images]
                }
            }
            this.loading = false
        },
        del() {
            let data = this.$refs.multipleTable.selection;
            if (!data.length) {
                this.$message.warning("请至少选择一个选项");
                return false;
            }
            let ids = [];
            for (let item of data) {
                ids.push(item.id);
            }
            this.$confirm("选中的选项将会被删除, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(async () => {
                let res = await this.$Http.delGoods({ id: ids.join(",") })
                if (res.status == 1) {
                    if (ids.length == this.tableData.length) {
                        console.log(1)
                        this.form.page -= 1
                        this.form.page = this.form.page < 1 ? 1 : this.form.page

                    }
                    this.$message.success('删除成功');
                    await this.getCompanyList()
                }

            })
        },
        handleClick(row, flag) {
            if (flag == 0) {
                //编辑
                this.$router.push(`/productManagement/productList/productDetail?title=编辑&id=${row.id}`)
            } else if (flag == 1) {
                //详情
               this.utils.goUrl('/storeManagement/delivery/materialsPut?id='+row.id)
            } else if (flag == 2) {
                this.$confirm("该条将会被删除, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(async () => {
                    let res = await this.$Http.delGoods({ id: row.id })
                    if (res.status == 1) {
                        if (this.tableData.length == 1) {
                            this.form.page -= 1
                            this.form.page = this.form.page < 1 ? 1 : this.form.page
                        }
                        this.$message.success('删除成功');
                        await this.getCompanyList()
                    }
                })
            } else {
                this.$router.push(`/productManagement/commentList?id=${row.id}`)
            }
        },
        handleSizeChange(val) {
            this.form.limit = val
            this.getCompanyList()
        },
        handleCurrentChange(val) {
            this.form.page = val
            this.getCompanyList()
        }
    }
}
</script>

<style lang="scss" scoped>
.app-container {
    .kong {
        height: 40px;
    }
    section {
        background: #eee;
        padding: 30px;
        .content {
            width: 100%;
            height: 100%;
            background: #fff;
            border-radius: 16px;
            padding-top: 18px;
            .top {
                padding-left: 29px;
            }
            ::v-deep .el-checkbox__input {
                margin-left: 10px;
            }
            ::v-deep .el-date-editor {
                width: -webkit-fill-available;
            }
        }
    }
}
</style>